package com.rs2hd.model;

import com.rs2hd.combat.Magic;
import com.rs2hd.combat.PlayerCombat;
import com.rs2hd.content.DeathEvent;
import com.rs2hd.content.PrayerManager.*;
import com.rs2hd.content.Food;
import com.rs2hd.model.InputHandler;
import com.rs2hd.model.Hits.Hit;
import com.rs2hd.net.ActionSender;
import com.rs2hd.util.ItemManager;
import com.rs2hd.net.Packet;
import com.rs2hd.packethandler.PacketHandlers;
import com.rs2hd.skills.cooking.Cooking;
import com.rs2hd.skills.smithing.Smithing;
import com.rs2hd.skills.woodcutting.Woodcutting;
import com.rs2hd.util.Misc;
import com.rs2hd.GameEngine;
import org.apache.mina.common.IoSession;
import java.util.*;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.net.InetSocketAddress;
import java.util.HashSet;
import java.util.Set;
import com.rs2hd.util.XStreamUtil;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.io.*;
import com.rs2hd.content.PlayerDrops;
import com.rs2hd.content.NPCDROP;
import com.rs2hd.model.NPC;


/**
 * Represents a connected player.
 *
 * @author Graham
 */
public class Player extends Entity {
    public transient boolean Attacking = false;
 
    public transient boolean AttackingNpc = false;
	private PlayerDetails details;
	private transient ActionSender actionSender;
	private transient Queue<Packet> queuedPackets;
	private transient PlayerUpdateFlags updateFlags;
	private transient Sprite sprite;
	private transient WalkingQueue walkingQueue;
	private transient LocalEntityList localEntities;
	private transient ChatMessage lastChatMessage;
	private transient int world;
	private transient Map<String, Object> temporaryAttributes;
	private transient Queue<Hit> queuedHits;
	private transient Bonuses bonuses;
	private transient boolean hd;
	private transient ForceText forceText;
	private transient ShopConfiguration shopConfiguration;
	private transient boolean busy;
	private transient DefencePrayer defencePrayer;
	private transient StrengthPrayer strengthPrayer;
	private transient AttackPrayer attackPrayer;
	private transient RangedPrayer rangedPrayer;
	private transient MagicPrayer magicPrayer;
	private transient ProtectionPrayer protectionPrayer;
	private transient OtherPrayer otherPrayer;
	private transient Request request;
	private transient Food food;
	private transient InputHandler input;
	private transient Cooking cooking;
	private transient Smithing smithing;
	private transient Woodcutting woodcutting;
	private transient InterfaceSwitches interfaceswitches;
	public transient PlayerCombat combat;
	private transient Magic magic;
	private Bank bank;
	private Settings settings;
	private Appearance appearance;
	private HeadIcons headIcons;
	private Equipment equipment;
	private Skills skills;
	private Inventory inventory;
	private Friends friends;
	private Specials specials;
	public int rights = 0;
	public int runEnergy = 100;
	public boolean inChat = false;
	private boolean onLogin;
	private int displayMode;
	private boolean fullScreen;
	public int clickX;
	public int clickY;
	public boolean following = false;
	public int followIndex = -1;
	public transient int potDelay = 0;
	public int banned = 0;
	public int ipbanned = 0;

	public boolean muted = false;
	public int KC;
	public int PkPoints;
	public int DC;
        public int fightStyle = 1;
	/** 
	 * Prayer
	 */
	public transient boolean PrayerON = false;
	public transient boolean QuickPrayer = false;
	public transient int prayerDrain = 100;
	public transient int drainRate = 0;
	public transient boolean THICKSKIN = false;
	public transient boolean BURSTOFSTRENGHT = false;
	public transient boolean CLARITYOFTHOUGHT = false;
	public transient boolean SHARPEYE = false;
	public transient boolean MYSTICWILL = false;
	public transient boolean ROCKSKIN = false;
	public transient boolean SUPERHUMANSTRENGHT = false;
	public transient boolean IMPROVEDREFLEXES = false;
	public transient boolean RAPIDRESTORE = false;
	public transient boolean RAPIDHEAL = false;
	public transient boolean PROTECTITEM = false;
	public transient boolean HAWKEYE = false;
	public transient boolean MYSTICLORE = false;
	public transient  boolean STEELSKIN = false;
	public transient boolean ULTIMATESTRENGHT = false;
	public transient boolean INCREDIBLEREFLEXES = false;
	public transient boolean PROTECTFROMSUMMONING = false;
	public transient boolean PROTECTFROMMAGIC = false;
	public transient boolean PROTECTFROMMISSELES = false;
	public transient boolean PROTECTFROMMELEE = false;
	public transient boolean EAGLEEYE = false;
	public transient boolean MYSTICMIGHT = false;
	public transient boolean RETRIBUTION = false;
	public transient boolean REDEMPTION = false;
	public transient boolean SMITE = false;
	public transient boolean CHILVALRY = false;
	public transient boolean PIETY = false;
	public  boolean QuickTHICKSKIN = false;
	public  boolean QuickBURSTOFSTRENGHT = false;
	public  boolean QuickCLARITYOFTHOUGHT = false;
	public  boolean QuickSHARPEYE = false;
	public  boolean QuickMYSTICWILL = false;
	public  boolean QuickROCKSKIN = false;
	public  boolean QuickSUPERHUMANSTRENGHT = false;
	public  boolean QuickIMPROVEDREFLEXES = false;
	public  boolean QuickRAPIDRESTORE = false;
	public  boolean QuickRAPIDHEAL = false;
	public  boolean QuickPROTECTITEM = false;
	public  boolean QuickHAWKEYE = false;
	public  boolean QuickMYSTICLORE = false;
	public  boolean QuickSTEELSKIN = false;
	public  boolean QuickULTIMATESTRENGHT = false;
	public  boolean QuickINCREDIBLEREFLEXES = false;
	public  boolean QuickPROTECTFROMSUMMONING = false;
	public  boolean QuickPROTECTFROMMAGIC = false;
	public  boolean QuickPROTECTFROMMISSELES = false;
	public  boolean QuickPROTECTFROMMELEE = false;
	public  boolean QuickEAGLEEYE = false;
	public  boolean QuickMYSTICMIGHT = false;
	public  boolean QuickRETRIBUTION = false;
	public  boolean QuickREDEMPTION = false;
	public  boolean QuickSMITE = false;
	public  boolean QuickCHILVALRY = false;
	public  boolean QuickPIETY = false;
	public int magicType;
	public transient int vengDelay;
	public transient boolean usingVeng;
	public transient long lastVengeance;
	public transient int vengUseDelay;
	public int frozen = 0;
	public int frozen1 = 0;
	public int Xlog = 0;
        public int serverMess = 180;
        public int serverMess1 = 0;
        
    // Trade variables
    public int tPartner = 0;
	public int[] tradeItems = new int[28];
	public int[] tradeItemsN = new int[28];
	public boolean[] tAccept = {false,false};
	public int tradePlayer = 0;
	
	public void setPkPoints(int setTo){
		PkPoints = setTo;
	}
	
	public void sm(String Msg) {
		getActionSender().sendMessage(Msg);
	}
	public int getEnemy() {
		return combat.enemyIndex;
	}

    public Set<String> bannedNames = new HashSet<String>();
    public Set<String> bannedAddresses = new HashSet<String>();

    public boolean canLogin(PlayerDetails details) {
        if (bannedNames.contains(Misc.formatPlayerNameForProtocol(details.getUsername()))) {
            return false;
        }
        InetSocketAddress addr = (InetSocketAddress) details.getSession().getRemoteAddress();
        if (bannedAddresses.contains(addr.getAddress().getHostAddress())) {
            return false;
        }
        if (bannedAddresses.contains(addr.getAddress().getHostName())) {
            return false;
        }
        return true;
    }

    public void save() {
        try {
            // TODO do in workerthread
            XStreamUtil.getXStream().toXML(this, new FileOutputStream("data/bans.xml"));
        } catch (FileNotFoundException e) {
        }
    }

     private static String[] bannedHosts = new String[500];

public void appendIPBan() {
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter("data/banned/bannedhosts.dat", true));
bw.newLine();
bw.flush();
} catch (IOException ioe) {
} finally {
if (bw != null) {
try {
bw.close();
} catch (IOException ioe2) {
}
}
}
}


    public void PvPDrop(Player player)
    {
        Item item = dropId(526);
        Item item1 = dropId(PlayerDrops.PvPDrop());
        Item item2 = dropId(PlayerDrops.PvPDrop1());
        Item item3 = dropId(PlayerDrops.PvPDrop2());
        Item item4 = dropId(PlayerDrops.PvPDrop3());
        if(player.getIndex() == getIndex())
        {
           //player.getActionSender().sendMessage(new StringBuilder()).append("You killed ").append(getUsername()).append(" but you did not get the drop.").toString());
             return;
        }
        if(item1.getDefinition() == null)
        {
             player.getActionSender().sendMessage("Your drop was nulled, fixing in a second.");
             return;
        }
        if(item != null && item1 != null && item2 != null && item3 != null && item4 != null)
        {
         World.getInstance().getItemManager().createDropGroundItem(this.getKiller() instanceof Player ? (Player) this.getKiller() : null, this.getLocation(), item);
         World.getInstance().getItemManager().createDropGroundItem(this.getKiller() instanceof Player ? (Player) this.getKiller() : null, this.getLocation(), item1);
         World.getInstance().getItemManager().createDropGroundItem(this.getKiller() instanceof Player ? (Player) this.getKiller() : null, this.getLocation(), item2);
         World.getInstance().getItemManager().createDropGroundItem(this.getKiller() instanceof Player ? (Player) this.getKiller() : null, this.getLocation(), item3);
         World.getInstance().getItemManager().createDropGroundItem(this.getKiller() instanceof Player ? (Player) this.getKiller() : null, this.getLocation(), item4);
        }
     }
 
    



     public static void loadBannedHosts() {
        int index = 0;
        try {
            BufferedReader in = new BufferedReader(new FileReader("./data/banned/bannedhosts.dat"));
            String loggedIPs = null;
            while ((loggedIPs = in.readLine()) != null) {
                bannedHosts[index] = loggedIPs;
                index++;
            }
        } catch (Exception e) {
            Misc.println("Error loading banned hosts list.");
            }
        }
	public int NPCMaxHitMelee() {
		int a = getSkills().getLevel(2);
		int b = bonuses.getBonus(10);
		double c = (double)a;
		double d = (double)b;
		double f = 0;
		double h = 0;
		f = (d*0.00175)+0.1;
		h = Math.floor(c*f+2.05);
		if(PIETY == true) {
			h *= 1.23;
		}
		if(FullDharokEquipped()) {
			int currHP = getSkills().getLevel(3);
			int HPlvl = getSkills().getLevelForXp(3);
			h +=((HPlvl-currHP)/2);
		}
		if(FullVoidMeleeEquipped()) {
			h *= 1.10;
		}
		if (getRandom(bonuses.getBonus(BestAttackBonus())+getSkills().getLevel(2)) > getRandom(getNpcMeleeDefence())) {
			return Misc.random(h);
		}else{
			return 0;
		}
	}
	  public void setEquipmentBonus() {
		int a = bonuses.getBonus(0);
		int b = bonuses.getBonus(1);
		int c = bonuses.getBonus(2);
		int d = bonuses.getBonus(5);
		int dc = bonuses.getBonus(6);
		int ds = bonuses.getBonus(7);
		int m = bonuses.getBonus(8);
		int mm = bonuses.getBonus(3);
		int e = bonuses.getBonus(10);
		int p = bonuses.getBonus(11);
		int s = bonuses.getBonus(12);
		int f = bonuses.getBonus(4);
		int g = bonuses.getBonus(9);
		getActionSender().sendString("Stab: "+a, 667, 36);
		getActionSender().sendString("Slash: "+b, 667, 37);
		getActionSender().sendString("Crush: "+c, 667, 38);
		getActionSender().sendString("Magic: "+mm, 667, 39);
		getActionSender().sendString("Ranged: "+f, 667, 40);
		getActionSender().sendString("Stab: "+d, 667, 41);
		getActionSender().sendString("Slash: "+dc, 667, 42);
		getActionSender().sendString("Crush: "+ds, 667, 43);
		getActionSender().sendString("Magic: "+m, 667, 44);
		getActionSender().sendString("Ranged: "+g, 667, 45);
		getActionSender().sendString("Strenght: +"+e, 667, 48);
		getActionSender().sendString("Ranged Str.: +"+s, 667, 50);
		getActionSender().sendString("Prayer: +"+p, 667, 49);
        getActionSender().sendString("Summoning: "+0, 667, 46);
	}
	public int getNpcMeleeDefence() {
		final NPC n = World.getInstance().getNpcList().get(getCombat().enemyId);
		switch (n.getId()) {
		case 1158:
			return 400;
		case 1160:
			if(FullVeracEquipped())
				return 400;
			else
				return 600;
		case 8324:
		case 8326:
		case 8327:
			return 150;
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
			return 3;

		case 134: return 90;
		case 1615: return 140;
		case 2614: return 230;
		case 5902: return 280;
		case 5253: return 190;
		case 6223: return 195;
		case 6225: return 210;
		case 6227: return 200;
		case 6222: return 190;
		case 6260: return 340;
		case 8133: return 500; //corp
		case 8349: return 350; //corp
		case 6261: return 230;
		case 6263: return 250;
		case 3847: return 230;
		case 1472: return 240;
		case 2745: return 130;
		case 2746: return 10;
		case 4284: return 150;
		case 4291: return 90;
		case 4292: return 95;
		case 6265: return 240;
		case 6625: return 150;
		case 6729: return 170;
		case 6247: return 290;
		case 6691: return 190;
		case 6998: return 180;	
		case 6999: return 160;
		case 7770: return 180;
		case 7771: return 420;

		default:
			return 20;
		}
	}

	public int getNpcRangeDefence() {
		final NPC n = World.getInstance().getNpcList().get(getCombat().enemyId);
		switch (n.getId()) {
		case 1158:
			return 450;
		case 1160:
			return 675;
		case 8324:
		case 8325:
		case 8327:
			return 200;
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
			return 3;

		case 134: return 90;
		case 1615: return 140;
		case 2614: return 230;
		case 5902: return 280;
		case 5253: return 190;
		case 6223: return 195;
		case 6225: return 210;
		case 6227: return 200;
		case 6222: return 190;
		case 6260: return 340;
		case 8133: return 550; //corp
		case 6261: return 230;
		case 6263: return 250;
		case 3847: return 230;
		case 1472: return 240;
		case 2745: return 130;
		case 2746: return 10;
		case 4284: return 150;
		case 4291: return 90;
		case 4292: return 95;
		case 6265: return 240;
		case 6625: return 150;
		case 6729: return 170;
		case 6247: return 290;
		case 6691: return 190;
		case 6998: return 180;	
		case 6999: return 160;
		case 7770: return 180;
		case 7771: return 420;

		default:
			return 20;
		}
	}
	public boolean wearingGMAUL() {
		return getEquipment().get(3) != null && getEquipment().get(3).getDefinition().getId() == 4153;
	}
	public int NPCMaxHitRange() {
		int a = getSkills().getLevel(4);
		int b = bonuses.getBonus(12);
		double c = (double)a;
		double d = (double)b;
		double f = 0;
		double h = 0;
		f = (d*0.00195)+0.1;
		h = Math.floor(c*f+2.05);
		if(EAGLEEYE == true) {
			h *= 1.15;
		}
		if(FullVoidRangeEquipped()) {
			h *= 1.10;
		}
		if (getRandom(bonuses.getBonus(4)+getSkills().getLevel(4)) > getRandom(getNpcRangeDefence())) {
			return (int) h;
		}else{
			return 0;
		}
		}
		public int getRandom(int range) {
			return (int)(Math.random() * (range + 1));
		}
		public int MaxHitSpec() {
			int a = getSkills().getLevel(2);
			int b = bonuses.getBonus(10);
			double c = (double)a;
			double d = (double)b;
			double f = 0;
			double h = 0;
			h = (d*0.00175)+2.6;
			if(PIETY == true) {
				h *= 1.23;
			}
			if(ULTIMATESTRENGHT == true) {
				h *= 1.15;
			}
			if(FullVoidMeleeEquipped()) {
				h *= 1.10;
			}
			if (!Defence()) {
				h = 0;
				return 0;
			}
			final Player p2 = World.getInstance().getPlayerList().get(getEnemy());
			if (p2!= null & p2.getEnemy() == this.getIndex()) {
				if (p2.DivineShieldEquipped() && p2.getSkills().getLevel(5) != 0) {
					double h2 = h*0.7;
					double prayDrain = (h-h2)/2;
					h = h2;
					p2.getSkills().DrainPray((int)prayDrain);

				}
				if (SMITE == true) {
					p2.getSkills().DrainPray((int) h / 4);
				}
			}

			return (int) Misc.random(h);
		}
                public void shop(Player player) {
                player.getActionSender().sendInterface(583);
                player.getActionSender().sendString("<col=ffffff>Dragon Claws 125 Shop Points", 583, 50);
                player.getActionSender().sendString("<col=ffffff>Hand Cannon 200 Shop Points", 583, 51);
                player.getActionSender().sendString("<col=ffffff>Vesta Chain 50 Shop Points", 583, 52);
                player.getActionSender().sendString("<col=ffffff>Vesta Skirt 50 Shop Points", 583, 53);
                player.getActionSender().sendString("<col=ffffff>Vesta Long 50 Shop Points", 583, 54);
                player.getActionSender().sendString("<col=ffffff>Statius Helm Shop Points", 583, 55);
                player.getActionSender().sendString("<col=ffffff>Statius Legs Shop Points", 583, 56);
                player.getActionSender().sendString("<col=ffffff>Statius Plate Shop Points", 583, 57);
                player.getActionSender().sendString("<col=ffffff>Veracs Set 80 Shop Points", 583, 58);
                player.getActionSender().sendString("<col=ffffff>Torags Set 80 Shop Points", 583, 59);
                player.getActionSender().sendString("<col=ffffff>Ahrims Set 80 Shop Points", 583, 71);
                player.getActionSender().sendString("<col=ffffff>Guthan Set 80 Shop Points", 583, 60);
                player.getActionSender().sendString("<col=ffffff>Dharoks Set 80 Shop Points", 583, 61);
                player.getActionSender().sendString("<col=ffffff>Fury Amulet 5 Shop Points", 583, 62);
                player.getActionSender().sendString("<col=ffffff>Armadyl GS 60 Shop Points", 583, 64);
                player.getActionSender().sendString("<col=ffffff>Saradomin GS 55 Shop Points", 583, 63);
                player.getActionSender().sendString("<col=ffffff>Bandos GS 50 Shop Points", 583, 65);
                player.getActionSender().sendString("<col=ffffff>Zamorak GS 45 Shop Points", 583, 70);
                player.getActionSender().sendString("<col=ffffff>Whip 15 Shop Points", 583, 66);
                player.getActionSender().sendString("<col=ffffff>Mage Book 15 Shop Points", 583, 67);
                player.getActionSender().sendString("<col=ffffff>X10 Home Teletabs 20 Shop Points", 583, 68);
                player.getActionSender().sendString("<col=ffffff>FireCape 150 Shop Points", 583, 69);
                player.getActionSender().sendString("<col=ffffff>Skillcape (t) Set 40 Shop Points", 583, 72);
                player.getActionSender().sendString("<col=ffffff>DFS 63 Shop Points", 583, 73);
                player.getActionSender().sendString("", 583, 74);
                player.getActionSender().sendString("", 583, 75);
                player.getActionSender().sendString("", 583, 76);
                player.getActionSender().sendString("", 583, 77);
                player.getActionSender().sendString("", 583, 78);
                player.getActionSender().sendString("", 583, 79);
                player.getActionSender().sendString("", 583, 80);
                player.getActionSender().sendString("", 583, 81);
                }
		public int MaxHitMelee() {
			int a = getSkills().getLevel(2);
			int b = bonuses.getBonus(10);
			double c = (double)a;
			double d = (double)b;
			double f = 0;
			double h = 0;
			f = (d*0.00175)+0.1;
			h = Math.floor(c*f+2.05);
			if(PIETY == true) {
				h *= 1.23;
			}
			if(ULTIMATESTRENGHT == true) {
				h *= 1.15;
			}
			if(FullDharokEquipped()) {
				int currHP = getSkills().getLevel(3);
				int HPlvl = getSkills().getLevelForXp(3);
				h +=((HPlvl-currHP)/2);
			}
			if(FullVoidMeleeEquipped()) {
				h *= 1.10;
			}
			if (!Defence()) {
				h = 0;
				return 0;
			}
			final Player p2 = World.getInstance().getPlayerList().get(getEnemy());
			if (p2!= null & p2.getEnemy() == this.getIndex()) {
				if (p2.DivineShieldEquipped() && p2.getSkills().getLevel(5) != 0) {
					double h2 = h*0.7;
					double prayDrain = (h-h2)/2;
					h = h2;
					p2.getSkills().DrainPray((int)prayDrain);

				}
				if (SMITE == true) {
					p2.getSkills().DrainPray((int) h / 4);
				}
			}

			return (int) Misc.random(h);
		}
		public boolean RDefence() {
			final Player p2 = World.getInstance().getPlayerList().get(getEnemy());
			if (p2 == null) {
				return true;
			}
			int att_def =  4;
			double attackBonus = (double) bonuses.getBonus(att_def);
			double attack = (double) getSkills().getLevel(4);
			if (SHARPEYE== true) {
				attack *= 1.05;
			}
			if (HAWKEYE == true) {
				attack *= 1.10;
			}
			if (EAGLEEYE == true) {
				attack *= 1.15;
			}
			double BestAttack = attackBonus + attack + (double)Misc.random(50);
			double defenceBonus = (double) p2.bonuses.getBonus(9);
			double defence = (double) p2.getSkills().getLevel(2);
			if (p2.THICKSKIN == true) {
				defence *= 1.05;
			}
			if (p2.ROCKSKIN == true) {
				defence *= 1.10;
			}
			if (p2.STEELSKIN == true) {
				defence *= 1.15;
			}
			if (p2.CHILVALRY == true) {
				defence *= 1.23;
			}
			if (p2.PIETY == true) {
				defence *= 1.25;
			}
			if (p2.PROTECTFROMMISSELES == true) {
				defenceBonus *= 1.50;
			}
			double BestDefence = defenceBonus + defence;
			if ((Misc.random(BestAttack)) > Misc.random(BestDefence)){
				return true;
			}
			return false;
		}
		public boolean FullDharokEquipped() {
			try {
				if(getEquipment().get(0).getDefinition().getId() == 4716 && getEquipment().get(4).getDefinition().getId() == 4720 && getEquipment().get(7).getDefinition().getId() == 4722 && getEquipment().get(3).getDefinition().getId() == 4718) {
					return true;
				}
				return false;	
			} catch (Exception e) {
				return false;	
			}			
		}
		public boolean DivineShieldEquipped() {
			try {
				if(getEquipment().get(5).getDefinition().getId() == 13740) {
					return true;
				}
				return false;	
			} catch (Exception e) {
				return false;	
			}			
		}
		public int MaxHitRange() {
			//Removed by request ~DKK
			return 5;
		}
		public boolean FullVeracEquipped() {
			try {
				if(getEquipment().get(0).getDefinition().getId() == 4753 && getEquipment().get(4).getDefinition().getId() == 4757 && getEquipment().get(7).getDefinition().getId() == 4759  && getEquipment().get(3).getDefinition().getId() == 4755) {
					return true;
				}
				return false;	
			} catch (Exception e) {
				return false;
			}
		}
		public boolean FullVoidMeleeEquipped() {
			try {
				if(getEquipment().get(0).getDefinition().getId() == 11665 && getEquipment().get(4).getDefinition().getId() == 8839 && getEquipment().get(7).getDefinition().getId() == 8840 && getEquipment().get(9).getDefinition().getId() == 8842) {
					return true;
				}
				return false;	
			} catch (Exception e) {
				return false;
			}
		}
		public boolean FullVoidRangeEquipped() {
			try {
				if(getEquipment().get(0).getDefinition().getId() == 11664 && getEquipment().get(4).getDefinition().getId() == 8839 && getEquipment().get(7).getDefinition().getId() == 8840 && getEquipment().get(9).getDefinition().getId() == 8842) {
					return true;
				}
				return false;	
			} catch (Exception e) {
				return false;	
			}		
		}
		public int BestAttackBonus() {
			if(bonuses.getBonus(0) > bonuses.getBonus(1) && bonuses.getBonus(0) > bonuses.getBonus(2)) {
				return 0;
			}
			if(bonuses.getBonus(1) > bonuses.getBonus(0) && bonuses.getBonus(1) > bonuses.getBonus(2)) {
				return 1;
			}
			if(bonuses.getBonus(2) > bonuses.getBonus(1) ||  bonuses.getBonus(2) > bonuses.getBonus(0)) {
				return 2;
			}
			return 1;
		}

		public int DefenceBonus(int BestAttackBonus) {
			if(BestAttackBonus == 0)
				return 5;
			if(BestAttackBonus == 1)
				return 6;
			if(BestAttackBonus == 2)
				return 7;
			return 5;
		}

		public boolean Defence() {
			final Player p2 = World.getInstance().getPlayerList().get(getEnemy());
			if (p2 == null) {
				return true;
			}
			int att_def =  BestAttackBonus();
			int def_att = DefenceBonus(att_def);
			double attackBonus = (double) bonuses.getBonus(att_def);
			double attack = (double) getSkills().getLevel(0);
			if (CLARITYOFTHOUGHT == true)
				attack *= 1.05;
			if (IMPROVEDREFLEXES == true)
				attack *= 1.10;
			if (INCREDIBLEREFLEXES == true)
				attack *= 1.15;
			if (CHILVALRY == true)
				attack *= 1.15;
			if (PIETY == true)
				attack *= 2.20;
			double BestAttack = attackBonus + attack + (double)Misc.random(50);
			double defenceBonus = (double) p2.bonuses.getBonus(def_att);
			double defence = (double) p2.getSkills().getLevel(1);
			if (p2.THICKSKIN == true)
				defence *= 1.05;
			if (p2.ROCKSKIN == true)
				defence *= 1.10;
			if (p2.STEELSKIN == true)
				defence *= 1.15;
			if (p2.CHILVALRY == true)
				defence *= 1.23;
			if (p2.PIETY == true)
				defence *= 1.25;
			if (p2.PROTECTFROMMELEE == true)
				defenceBonus *= 1.50;
			double BestDefence = defenceBonus + defence;
			if ((Misc.random(BestAttack)) > Misc.random(BestDefence)){
				return true;
			}
			return false;
		}

		public void resetFaceId() {
			//setEntityFocus(new EntityFocus(-1));
		}

    public Item dropId(int id) {
	return new Item(id);
    }

		public void setDefencePrayer(DefencePrayer defencePrayer) {
			this.defencePrayer = defencePrayer;
		}

		public void setStrengthPrayer(StrengthPrayer strengthPrayer) {
			this.strengthPrayer = strengthPrayer;
		}

		public void setAttackPrayer(AttackPrayer attackPrayer) {
			this.attackPrayer = attackPrayer;
		}

		public void setRangedPrayer(RangedPrayer rangedPrayer) {
			this.rangedPrayer = rangedPrayer;
		}

		public void setMagicPrayer(MagicPrayer magicPrayer) {
			this.magicPrayer = magicPrayer;
		}

		public void setProtectionPrayer(ProtectionPrayer protectionPrayer) {
			this.protectionPrayer = protectionPrayer;
		}

		public void setOtherPrayer(OtherPrayer otherPrayer) {
			this.otherPrayer = otherPrayer;
		}

		public DefencePrayer getDefencePrayer() {
			return defencePrayer;
		}

		public StrengthPrayer getStrengthPrayer() {
			return strengthPrayer;
		}

		public AttackPrayer getAttackPrayer() {
			return attackPrayer;
		}

		public RangedPrayer getRangedPrayer() {
			return rangedPrayer;
		}

		public MagicPrayer getMagicPrayer() {
			return magicPrayer;
		}

		public ProtectionPrayer getProtectionPrayer() {
			return protectionPrayer;
		}

		public OtherPrayer getOtherPrayer() {
			return otherPrayer;
		}

		public Player(PlayerDetails details) {
			if(magicType == 0) {
				magicType = 193;
			}
			this.details = details;
			this.appearance = new Appearance();
			this.headIcons = new HeadIcons();
			this.equipment = new Equipment();
			this.skills = new Skills();
			this.inventory = new Inventory();
			this.friends = new Friends();
			this.settings = new Settings();
			this.bank = new Bank();
			this.settings.setDefaultSettings();
			this.specials = new Specials();
		}

		/**
		 * Called when XStream loads us.
		 * <p/>
		 * NOTE: other loaders should call this also.
		 */
		public Object readResolve() {
			super.readResolve();
			actionSender = new ActionSender(this);
			queuedPackets = new LinkedList<Packet>();
			updateFlags = new PlayerUpdateFlags();
			sprite = new Sprite();
			walkingQueue = new WalkingQueue(this);
			skills.setPlayer(this);
			inventory.setPlayer(this);
			bank.setPlayer(this);
			equipment.setPlayer(this);
			friends.setPlayer(this);
			localEntities = new LocalEntityList();
			settings.setPlayer(this);
			specials.setPlayer(this);
			combat = new PlayerCombat(this);
			temporaryAttributes = new HashMap<String, Object>();
			lastChatMessage = null;
			world = 66;
			details.refreshLongName();
			queuedHits = new LinkedList<Hit>();
			bonuses = new Bonuses(this);
			hd = false;
			shopConfiguration = new ShopConfiguration();
			busy = false;
			request = new Request(this);
			food = new Food(this);
			input = new InputHandler(this);
			cooking = new Cooking(this);
			smithing = new Smithing(this);
			woodcutting = new Woodcutting(this);
			interfaceswitches = new InterfaceSwitches(this);
			magic = new Magic(this);

			return this;
		}
		public void resetSkills() {
			getCooking().setCooking(false);
			getSmithing().setSmithing(false);
			getWoodcutting().resetWoodcutting();
		}
		public Request getRequests() {
			return request;
		}

		public boolean isBusy() {
			return busy;
		}
	

		public void setBusy(boolean b) {
			this.busy = b;
			if (busy) {
				this.setAttacking(false);
			}
		}


		/**
		 * Called roughly every 500ms.
		 */
		public void tick() {
			if (vengDelay > 0) {
				vengDelay--;
			}
			if (vengUseDelay > 0) {
				vengUseDelay--;
			}
			if (potDelay > 0) {
				potDelay--;
			}
                if(serverMess > 0){
			serverMess--;
		}
		if(serverMess == 0 && serverMess1 == 0){
			serverMess1 = 1;
			getActionSender().sendMessage("<col=0066ff>[SERVER]:<col=ff0033>Vote for WinnerScape at WinnerScape.com!");
			serverMess = 60;
		}
		if(serverMess == 0 && serverMess1 == 1){
			serverMess1 = 2;
			getActionSender().sendMessage("<col=0066ff>[SERVER]:<col=ff0033>We would love to hear you suggestions to make this the best server!  Post them on the forums.");
			serverMess = 60;
		}
		if(serverMess == 0 && serverMess1 == 2){
			serverMess1 = 3;
			getActionSender().sendMessage("<col=0066ff>[SERVER]:<col=ff0033>To Use Bank Go To Graphic Option And Click On Fixed Not Resisable!");
			serverMess = 60;
		}
		if(serverMess == 0 && serverMess1 == 3){
			serverMess1 = 4;
			getActionSender().sendMessage("<col=0066ff>[SERVER]:<col=ff0033>Respect ALL Mods And Admins, Enjoy WinnerScape!.");
			serverMess = 60;
		}
		if(serverMess == 0 && serverMess1 == 4){
			serverMess1 = 0;
			getActionSender().sendMessage("<col=0066ff>[SERVER]:<col=ff0033>Dangerous Pking Locations are ::Edge And ::Dragpk!.");
			serverMess = 60;
		        }
			if (vengUseDelay <= 0 && usingVeng) {
				vengUseDelay = 0;
				usingVeng = false;
				getActionSender().sendMessage("Vengeance has faded away.");
			}
			if (PrayerON) {
				int drain = (drainRate - bonuses.getBonus(11));

				if (drain <= 0)
					drain = 1;

				prayerDrain -= (drain);
				if(prayerDrain <= 0 && getSkills().getLevel(5) > 0) {
					getSkills().DrainPray(1);
					prayerDrain = 100;
				}
				if(getSkills().getLevel(5) <= 0) {
					GameEngine.prayer.PrayerOff(this);
					sm("You have run out of prayer points.");
					prayerDrain = 100;
				}

			}
			if (frozen > 0) {
				frozen--;
			}
			if (frozen1 > 0) {
				frozen1--;
			}
}


		public void setTemporaryAttribute(String attribute, Object value) {
			temporaryAttributes.put(attribute, value);
		}

		public Object getTemporaryAttribute(String attribute) {
			return temporaryAttributes.get(attribute);
		}

		public void removeTemporaryAttribute(String attribute) {
			temporaryAttributes.remove(attribute);
		}

		public Settings getSettings() {
			return this.settings;
		}

		public PlayerDetails getPlayerDetails() {
			return this.details;
		}

		public ActionSender getActionSender() {
			return this.actionSender;
		}

		public IoSession getSession() {
			return this.details.getSession();
		}

		public String getUsername() {
			return this.details.getUsername();
		}

		public int getRights() {
			return this.rights;
		}

		public void processQueuedPackets() {
			synchronized (queuedPackets) {
				Packet p = null;
				while ((p = queuedPackets.poll()) != null) {
					PacketHandlers.handlePacket(getSession(), p);
				}
			}
		}

		public void addPacketToQueue(Packet p) {
			synchronized (queuedPackets) {
				queuedPackets.add(p);
			}
		}

		public PlayerUpdateFlags getUpdateFlags() {
			return updateFlags;
		}

		public Sprite getSprites() {
			return sprite;
		}

		public Appearance getAppearance() {
			return appearance;
		}

		public HeadIcons getHeadIcons() {
			return headIcons;
		}

		public Food getFood() {
			return food;
		}

		public Equipment getEquipment() {
			return equipment;
		}

		public WalkingQueue getWalkingQueue() {
			return walkingQueue;
		}

		public Skills getSkills() {
			return skills;
		}

		public boolean isDisconnected() {
			return !getSession().isConnected();
		}

		public void setPlayerListSize(int playerListSize) {
			localEntities.playerListSize = playerListSize;
		}

		public int getPlayerListSize() {
			return localEntities.playerListSize;
		}
		public InputHandler getInputHandler() {
			return input;
		}

		public void setPlayerList(Player[] playerList) {
			localEntities.playerList = playerList;
		}

		public Player[] getPlayerList() {
			return localEntities.playerList;
		}

		public void setPlayersInList(byte[] playersInList) {
			localEntities.playersInList = playersInList;
		}

		public byte[] getPlayersInList() {
			return localEntities.playersInList;
		}


		public void setNpcListSize(int npcListSize) {
			localEntities.npcListSize = npcListSize;
		}

		public int getNpcListSize() {
			return localEntities.npcListSize;
		}

		public void setNpcList(NPC[] npcList) {
			localEntities.npcList = npcList;
		}

		public NPC[] getNpcList() {
			return localEntities.npcList;
		}

		public void setNpcsInList(byte[] npcsInList) {
			localEntities.npcsInList = npcsInList;
		}

		public byte[] getNpcsInList() {
			return localEntities.npcsInList;
		}

		public Inventory getInventory() {
			return inventory;
		}

		public ChatMessage getLastChatMessage() {
			return lastChatMessage;
		}

		public void setLastChatMessage(ChatMessage msg) {
			lastChatMessage = msg;
		}

		public int getWorld() {
			return world;
		}

		public Friends getFriends() {
			return friends;
		}

		public boolean isRebuildNpcList() {
			return localEntities.rebuildNpcList;
		}

		public void setForceText(ForceText forceText) {
			this.forceText = forceText;
			updateFlags.setForceTextUpdateRequired(true);
		}

		public void forceChat(String message) {
			setForceText(new ForceText(message));
			updateFlags.setForceTextUpdateRequired(true);
			System.out.println("DONE");
		}

		public ForceText getForceText() {
			return forceText;
		}

		public void graphics(int id) {
			graphics(id, 0);
		}

		public void graphics(int id, int delay) {
			this.setLastGraphics(new Graphics(id, delay));
			updateFlags.setGraphicsUpdateRequired(true);
		}

		public void animate(int id) {
			animate(id, 0);
		}

		public void animate(int id, int delay) {
			this.setLastAnimation(new Animation(id, delay));
			updateFlags.setAnimationUpdateRequired(true);
		}

		public void setRebuildNpcList(boolean b) {
			this.localEntities.rebuildNpcList = true;
		}

		public void processQueuedHits() {
			if (!updateFlags.isHitUpdateRequired()) {
				if (queuedHits.size() > 0) {
					Hit h = queuedHits.poll();
					hit(h.getDamage(), h.getType());
				}
			}
			if (!updateFlags.isHit2UpdateRequired()) {
				if (queuedHits.size() > 0) {
					Hit h = queuedHits.poll();
					hit(h.getDamage(), h.getType());
				}
			}
		}

		public void heal(int amount) {
			skills.heal(amount);
		}

		public void hit(int damage) {
			if (damage == 0) {
				hit(damage, Hits.HitType.NO_DAMAGE);
			} else {
				hit(damage, Hits.HitType.NORMAL_DAMAGE);
			}
		}

		public void tele(int x, int y, int h) {
			Location tele = null;
			try {
				tele = Location.location(x, y, h);
			} catch (Exception e) {
				tele = Location.location(x, y, 0);
			}
			teleport(tele);
		}

		public void hit(int damage, Hits.HitType type) {
			int hp = this.getSkills().getLevelForXp(Skills.HITPOINTS);
			if (damage > hp) {
				damage = hp;
			}
			if (!updateFlags.isHitUpdateRequired()) {
				getHits().setHit1(new Hit(damage, type));
				updateFlags.setHitUpdateRequired(true);
			} else {
				if (!updateFlags.isHit2UpdateRequired()) {
					getHits().setHit2(new Hit(damage, type));
					updateFlags.setHit2UpdateRequired(true);
				} else {
					queuedHits.add(new Hit(damage, type));
				}
			}
			skills.hit(damage);
			if (skills.getLevel(Skills.HITPOINTS) <= 0) {
				if (!this.isDead()) {
					World.getInstance().registerEvent(new DeathEvent(this));
				}
				this.setDead(true);
			}
		}

		public Bank getBank() {
			return bank;
		}

		public void setRunEnergy(int runEnergy) {
			this.runEnergy = runEnergy;
			actionSender.sendEnergy();
		}

		public int getRunEnergy() {
			return this.runEnergy;
		}

		public Bonuses getBonuses() {
			return this.bonuses;
		}

		public void setHd(boolean b) {
			this.hd = b;
			if (b) {
				this.getActionSender().sendHdLogin();
			}
		}

		public boolean isHd() {
			return hd;
		}

		public void turnTo(Entity entity) {
			this.getUpdateFlags().setFaceToUpdateRequired(true, entity.getClientIndex());
		}

		public void turnTemporarilyTo(Entity entity) {
			this.getUpdateFlags().setFaceToUpdateRequired(true, entity.getClientIndex());
			this.getUpdateFlags().setClearFaceTo(true);
		}

		public ShopConfiguration getShopConfiguration() {
			return shopConfiguration;
		}

		public boolean bountyArea()
		{
			return getLocation().getX() >= 3085 && getLocation().getX() <= 3185 && getLocation().getY() >= 3662 && getLocation().getY() <= 3765;
		}

		public boolean corp()
		{
			return getLocation().getX() >= 2960 && getLocation().getX() <= 2999 && getLocation().getY() >= 4390 && getLocation().getY() <= 4440;
		}


		public boolean CantTeleZone()
		{
			return getLocation().getX() >= 2949 && getLocation().getX() <= 3400 && getLocation().getY() >= 3525 && getLocation().getY() <= 4462;
		}

		public boolean Spawn()
		{
			return getLocation().getX() >= 1619 && getLocation().getX() <= 1699 && getLocation().getY() >= 5659 && getLocation().getY() <= 5739;
		}

		public boolean CantEatZone()
		{
			return getLocation().getX() >= 2816 && getLocation().getX() <= 2875 && getLocation().getY() >= 2958 && getLocation().getY() <= 2968;
		}

		public boolean SafeZone()
		{
			return getLocation().getX() >= 2508 && getLocation().getX() <= 2525 && getLocation().getY() >= 3851 && getLocation().getY() <= 3874
			|| getLocation().getX() >= 2508 && getLocation().getX() <= 2525 && getLocation().getY() >= 3851 && getLocation().getY() <= 3874
			|| getLocation().getX() >= 2438 && getLocation().getX() <= 2446 && getLocation().getY() >= 3082 && getLocation().getY() <= 3098
			|| getLocation().getX() >= 2394 && getLocation().getX() <= 2408 && getLocation().getY() >= 5168 && getLocation().getY() <= 5175
			|| getLocation().getX() >= 3200 && getLocation().getX() <= 3229 && getLocation().getY() >= 3200 && getLocation().getY() <= 3233
			|| getLocation().getX() >= 3135 && getLocation().getX() <= 3204 && getLocation().getY() >= 3652 && getLocation().getY() <= 3663
			|| getLocation().getX() >= 3147 && getLocation().getX() <= 3199 && getLocation().getY() >= 3663 && getLocation().getY() <= 3681
			|| getLocation().getX() >= 3158 && getLocation().getX() <= 3199 && getLocation().getY() >= 3681 && getLocation().getY() <= 3693
			|| getLocation().getX() >= 3176 && getLocation().getX() <= 3191 && getLocation().getY() >= 3693 && getLocation().getY() <= 3703
			|| getLocation().getX() >= 2948 && getLocation().getX() <= 2949 && getLocation().getY() >= 3368 && getLocation().getY() <= 3369
			|| getLocation().getX() >= 3221 && getLocation().getX() <= 3224 && getLocation().getY() >= 3223 && getLocation().getY() <= 3225
			|| getLocation().getX() >= 2526 && getLocation().getX() <= 2554 && getLocation().getY() >= 4707 && getLocation().getY() <= 4725
			|| getLocation().getX() >= 3250 && getLocation().getX() <= 3257 && getLocation().getY() >= 3419 && getLocation().getY() <= 3423
			|| getLocation().getX() >= 3179 && getLocation().getX() <= 3194 && getLocation().getY() >= 3432 && getLocation().getY() <= 3446
			|| getLocation().getX() >= 2943 && getLocation().getX() <= 2947 && getLocation().getY() >= 3368 && getLocation().getY() <= 3373
			|| getLocation().getX() >= 3009 && getLocation().getX() <= 3018 && getLocation().getY() >= 3353 && getLocation().getY() <= 3358
			|| getLocation().getX() >= 3091 && getLocation().getX() <= 3098 && getLocation().getY() >= 3488 && getLocation().getY() <= 3499
			|| getLocation().getX() >= 3065 && getLocation().getX() <= 3112 && getLocation().getY() >= 3520 && getLocation().getY() <= 3523
			|| getLocation().getX() >= 3264 && getLocation().getX() <= 3279 && getLocation().getY() >= 3672 && getLocation().getY() <= 3695
			|| getLocation().getX() >= 3137 && getLocation().getX() <= 3193 && getLocation().getY() >= 3467 && getLocation().getY() <= 3518
			|| getLocation().getX() >= 3301 && getLocation().getX() <= 3309 && getLocation().getY() >= 3116 && getLocation().getY() <= 3132
                        || getLocation().getX() >= 3287 && getLocation().getX() <= 3285 && getLocation().getY() >= 3879 && getLocation().getY() <= 3891
                        || getLocation().getX() >= 3280 && getLocation().getX() <= 3285 && getLocation().getY() >= 3887 && getLocation().getY() <= 3884
                        || getLocation().getX() >= 2950 && getLocation().getX() <= 2939 && getLocation().getY() >= 4376 && getLocation().getY() <= 4389
			|| getLocation().getX() >= 3228 && getLocation().getX() <= 3257 && getLocation().getY() >= 3523 && getLocation().getY() <= 3523
                        || getLocation().getX() >= 3292 && getLocation().getX() <= 3287 && getLocation().getY() >= 3879 && getLocation().getY() <= 3891
                        || getLocation().getX() >= 2931 && getLocation().getX() <= 2957 && getLocation().getY() >= 4366 && getLocation().getY() <= 4392
                        || getLocation().getX() >= 3424 && getLocation().getX() <= 3430 && getLocation().getY() >= 2889 && getLocation().getY() <= 2894
                        || getLocation().getX() >= 3292 && getLocation().getX() <= 3280 && getLocation().getY() >= 3891 && getLocation().getY() <= 3879
                        || getLocation().getX() >= 3285 && getLocation().getX() <= 3292 && getLocation().getY() >= 3883 && getLocation().getY() <= 3888
                        || getLocation().getX() >= 3287 && getLocation().getX() <= 3292 && getLocation().getY() >= 3889 && getLocation().getY() <= 3891
                        || getLocation().getX() >= 3285 && getLocation().getX() <= 3289 && getLocation().getY() >= 3879 && getLocation().getY() <= 3882
                        || getLocation().getX() >= 3280 && getLocation().getX() <= 3284 && getLocation().getY() >= 3885 && getLocation().getY() <= 3886
                        || getLocation().getX() >= 3281 && getLocation().getX() <= 3282 && getLocation().getY() >= 3884 && getLocation().getY() <= 3887
                        || getLocation().getX() >= 2843 && getLocation().getX() <= 2945 && getLocation().getY() >= 2952 && getLocation().getY() <= 2956
                        || getLocation().getX() >= 2858 && getLocation().getX() <= 2561 && getLocation().getY() >= 2952 && getLocation().getY() <= 2956
                        || getLocation().getX() >= 2436 && getLocation().getX() <= 2448 && getLocation().getY() >= 3080 && getLocation().getY() <= 3099
                        || getLocation().getX() >= 2849 && getLocation().getX() <= 2855 && getLocation().getY() >= 2951 && getLocation().getY() <= 2957
                        || getLocation().getX() >= 2447 && getLocation().getX() <= 2470 && getLocation().getY() >= 3064 && getLocation().getY() <= 3111;
		}
		public boolean inEdgePk()
		{
			return getLocation().getX() >= 3040 && getLocation().getX() <= 3118 && getLocation().getY() >= 3522 && getLocation().getY() <= 3553 
			|| getLocation().getX() >= 3316 && getLocation().getX() <= 3369 && getLocation().getY() >= 3636 && getLocation().getY() <= 3738
			|| getLocation().getX() >= 3068 && getLocation().getX() <= 3150 && getLocation().getY() >= 3464 && getLocation().getY() <= 3520;
		}

		public boolean NPK()
		{
			return getLocation().getX() >= 3195 && getLocation().getX() <= 3178 && getLocation().getY() >= 3450 && getLocation().getY() <= 3447;
		}

		public boolean NormalZone()
		{
			return getLocation().getX() >= 2852 && getLocation().getX() <= 2862 && getLocation().getY() >= 2962 && getLocation().getY() <= 2969
			|| getLocation().getX() >= 2816 && getLocation().getX() <= 2875 && getLocation().getY() >= 2958 && getLocation().getY() <= 2968
			|| getLocation().getX() >= 3040 && getLocation().getX() <= 3118 && getLocation().getY() >= 3522 && getLocation().getY() <= 3553 
			|| getLocation().getX() >= 3316 && getLocation().getX() <= 3369 && getLocation().getY() >= 3636 && getLocation().getY() <= 3738
			|| getLocation().getX() >= 2816 && getLocation().getX() <= 2879 && getLocation().getY() >= 2931 && getLocation().getY() <= 2994
			|| getLocation().getX() >= 3068 && getLocation().getX() <= 3150 && getLocation().getY() >= 3464 && getLocation().getY() <= 3520
			|| getLocation().getX() >= 2364 && getLocation().getX() <= 2435 && getLocation().getY() >= 3068 && getLocation().getY() <= 3140;
		}

		@Override
		public void resetTurnTo() {
			this.getUpdateFlags().setFaceToUpdateRequired(true, 0);
		}

		@Override
		public int getAttackAnimation() {
			return !this.appearance.isNpc() ? equipment.getAttackAnimation() : NPCDefinition.forId(this.appearance.getNpcId()).getAttackAnimation();
		}

		@Override
		public int getAttackSpeed() {
			return equipment.getAttackSpeed();
		}


		@Override
		public int getDefenceAnimation() {
			return !this.appearance.isNpc() ? equipment.getDefenceAnimation() : NPCDefinition.forId(this.appearance.getNpcId()).getDefenceAnimation();
		}

		@Override
		public boolean isAnimating() {
			return this.getUpdateFlags().isAnimationUpdateRequired();
		}

		@Override
		public boolean isDestroyed() {
			return !World.getInstance().getPlayerList().contains(this);
		}

		@Override
		public int getDeathAnimation() {
			return !this.appearance.isNpc() ? 7197 : NPCDefinition.forId(this.appearance.getNpcId()).getDeathAnimation();
		}

		@Override
		public int getHp() {
			return this.getSkills().getLevel(Skills.HITPOINTS);
		}

		@Override
		public int getMaxHp() {
			return this.getSkills().getLevelForXp(Skills.HITPOINTS);
		}

		@Override
		public void setHp(int val) {
			this.getSkills().set(Skills.HITPOINTS, val);
		}
		

		@Override
		public void dropLoot() {
			List<Item> itemsInHand = new ArrayList<Item>();
			for (int i = 0; i < Inventory.SIZE; i++) {
				Item item = this.getInventory().getContainer().get(i);
				if (item != null) {
					itemsInHand.add(item);
				}
			}
			for (int i = 0; i < Equipment.SIZE; i++) {
				Item item = this.getEquipment().getContainer().get(i);
				if (item != null) {
					itemsInHand.add(item);
				}
			}
			this.getInventory().reset();
			this.getEquipment().reset();
			int keep = 3;
			if (this.getHeadIcons().isSkulled()) {
				keep = 0;
			}
			if (keep > 0) {
				Collections.sort(itemsInHand, new Comparator<Item>() {
					@Override
					public int compare(Item arg0, Item arg1) {
						int a0 = arg0.getDefinition().getPrice().getNormalPrice();
						int a1 = arg1.getDefinition().getPrice().getNormalPrice();
						return a1 - a0;
					}
				});
				List<Item> toRemove = new ArrayList<Item>();
				for (int i = 0; i < itemsInHand.size(); i++) {
					Item item = itemsInHand.get(i);
					if (item.getDefinition().isStackable() || item.getDefinition().isNoted()) {
						continue;
					}
					if (keep > 0) {
						toRemove.add(item);
						keep--;
					} else {
						break;
					}
				}
				for (Item i : toRemove) {
					itemsInHand.remove(i);
					this.getInventory().addItem(i.getId(), 1);
				}
			}
			for (Item i : itemsInHand) {
				World.getInstance().getItemManager().createDropGroundItem(this.getKiller() instanceof Player ? (Player) this.getKiller() : null, this.getLocation(), i);
		

			}
		}


		

		public Specials getSpecials() {
			return specials;
		}
		@Override
		public int getMaxHit() {
			return 0;
		}
		@Override
		public boolean isAutoRetaliating() {
			return settings.isAutoRetaliate();
		}
		@Override
		public int getDrawBackGraphics() {
			return equipment.getDrawBackGraphics();
		}

		@Override
		public int getProjectileId() {
			return equipment.getProjectileId();
		}

		@Override
		public boolean hasAmmo() {
			return equipment.hasAmmo();
		}

		public void destroy() {
			GameEngine.ClanMain.leaveChat(this);
			if (request.isTrading()) {
				request.getTrade().close();
			}
		}

		public void setCooking(Cooking cooking) {
			this.cooking = cooking;
		}

		public Cooking getCooking() {
			return cooking;
		}

		public Smithing getSmithing() {
			return smithing;
		}
		public Woodcutting getWoodcutting() {
			return woodcutting;
		}
		public void setOnLogin(boolean onLogin) {
			this.onLogin = onLogin;
		}

		public boolean isOnLogin() {
			return onLogin;
		}
		public InterfaceSwitches getInterfaceswitches() {
			return interfaceswitches;
		}
		public void setDisplayMode(int displayMode) {
			this.displayMode = displayMode;
		}

		public int getDisplayMode() {
			return displayMode;
		}
		public void setFullScreen(boolean fullScreen) {
			this.fullScreen = fullScreen;
		}

		public boolean isFullScreen() {
			return fullScreen;
		}
		public PlayerCombat getCombat() {
			return combat;
		}
		public void setEnemy(int index) {
			getCombat().enemyIndex = index;
		}
		public void setAttacking(boolean bool) {
			getCombat().attacking = bool;
		}
		public void setSpecial(boolean bool) {
			getCombat().useSpec = bool;
		}
		public void setAttackStyle(int i) {
			getCombat().attackStyle = i;
		}
		public int getAttackStyle() {
			return getCombat().attackStyle;
		}
		public Magic getMagic() {
			return magic;
		}
	}
